package com.lty.practice.zookeeper.controller;

import com.lty.practice.zookeeper.component.FirstServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
public class SecondController {
    private final String url="http://zk-first";

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private FirstServiceClient firstServiceClient;

    @GetMapping("/firstCall")
    public String firstCall() {
        log.info("this is first call");
        String res = restTemplate.getForObject(url+"/zkTest",String.class);
        log.info("this is first call response:{}", res);
        return res;
    }

    @GetMapping("/secondCall")
    public String secondCall() {
        log.info("this is second call");
        String res = firstServiceClient.zkTest();
        log.info("this is second call response:{}", res);
        return res;
    }
}
